from appium.webdriver.common.appiumby import AppiumBy as By
from pages.base_page import BasePage

# 定位器
my_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().text("我")')
recipe_locator = (By.XPATH, '//android.widget.TextView[@text="菜谱 1"]')
search_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/ib_search")')
search_edit_text_locator = (By.ID, 'com.xiachufang:id/search_edit_text')
search_text_locator=(By.ANDROID_UIAUTOMATOR,'new UiSelector().text("搜索")')
common_first_text_locator=(By.ID,'com.xiachufang:id/common_first_text')
item_img_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_img")')
description_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().description("更多操作")')
item_share_icon_locator_11 = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("com.xiachufang:id/item_share_icon").instance(9)')
button1_locator = (By.ANDROID_UIAUTOMATOR, 'new UiSelector().resourceId("android:id/button1")')

class MySearchRecipePage(BasePage):

    def click_my(self):
        """
        点击我
        :return:
        """
        self.find_element(my_locator).click()

    def click_recipe(self):
        """
        点击菜谱
        :return:
        """
        self.find_element(recipe_locator).click()
    def click_search(self):
        """
        点击搜索
        :return:
        """
        self.find_element(search_locator).click()

    def input_search_edit_text(self):
        """
        输入搜索内容
        :param text:
        :return:
        """
        self.find_element(search_edit_text_locator).send_keys("红枣")

    def click_search_text(self):
        """
        点击搜索
        :return:
        """
        self.find_element(search_text_locator).click()
    def get_common_first_text(self):
        """
        获取搜索结果
        :return:
        """
        return self.find_element(common_first_text_locator).text

    def click_item_img(self):
        """
        点击菜谱图片
        :return:
        """
        self.find_element(item_img_locator).click()

    def click_description(self):
        """
        点击更多操作
        :return:
        """
        self.find_element(description_locator).click()

    def swipe_recipe(self):
        """
        滑动
        :return:
        """
        self.driver.swipe(950, 2100, 150, 2100, 1000)

    def click_item_share_icon_11(self):
        """
        点击删除
        :return:
        """
        self.find_element(item_share_icon_locator_11).click()

    def click_button1(self):
        """
        点击确定
        :return:
        """
        self.find_element(button1_locator).click()
